/**
 * 作者: hxl
 * 日期: 2025-07-24 11:29:29
 * 备注: 用户限时商店表
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.server.game.commondata.shop.Shop;
import com.motu.monstercity.server.game.commondata.shop.ShopConstant;
import com.motu.monstercity.server.game.logic.ShopManager;
import com.motu.vertx.module.utility.model.EntityManager;
import com.motu.vertx.module.utility.toolset.TimeUtils;

public class UserRankActShop extends UserRankActShopModel {
    public UserRankActShop() {
        super();
    }
    public UserRankActShop(long userId, int configId, int shopId, int num) {
        putUserId(userId);
        putConfigId(configId);
        putShopId(shopId);
        putNum(num);
        String actListKey = EntityManager.getFieldJoinString(userId, configId);
        putActListKey(actListKey);
        putResetTime(TimeUtils.getCurTime());
    }

    public void reset() {
        Shop shop = ShopManager.getShop(shopId);
        if (shop == null) {
            return;
        }
        long curTime = TimeUtils.getCurTime();
        boolean update = false;
        if (shop.getLimitType() == ShopConstant.SHOP_LIMIT_TYPE_1) {
            if (!TimeUtils.isToday(resetTime)) {
                update = true;
            }
        } else if (shop.getLimitType() == ShopConstant.SHOP_LIMIT_TYPE_2) {
            if (!TimeUtils.isSameWeek(resetTime, curTime)) {
                update = true;
            }
        }
        if (update) {
            putNum(0);
            putResetTime(curTime);
            update();
        }
    }

}
